package org.edu.modules.research.rpaper.service.impl;

import cn.hutool.core.util.StrUtil;
import org.apache.shiro.SecurityUtils;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.system.vo.LoginUser;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.research.rpaper.mapper.VeJkyReportMapper;
import org.edu.modules.research.rpaper.entity.VeJkyReport;
import org.edu.modules.research.rpaper.dto.VeJkyReportDto;
import org.edu.modules.research.rpaper.service.VeJkyReportService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;


/**
 * 实现类
 */
@Service
public class VeJkyReportServiceImpl extends BaseServiceImpl<VeJkyReport, VeJkyReportMapper> implements VeJkyReportService {

    public IPage<VeJkyReportDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeJkyReportDto findDtoById(String id) {
        VeJkyReport entity = super.findById(id);
        VeJkyReportDto dto = ConvertUtils.convertToDto(entity, VeJkyReportDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeJkyReportDto dto,Boolean isAdd){
        if(isAdd){
            LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            if (loginUser != null && loginUser.getId() != null) {
                dto.setUserId(loginUser.getId());
                dto.setUserName(loginUser.getRealname());
            }
            super.insert(dto);
        }else{
            super.update(dto);
        }
    }

}
